package studio.raptor.hub.in.server;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import org.apache.http.client.HttpClient;
import studio.raptor.hub.in.ServerProxy;

/**
 * Created by liuyong8 on 2017/7/27.
 */
public class AccountProxy extends ServerProxy {
//    {
//        "qryAccount": {
//        "acctId": 1000000000003729
//    }
//    }
//{"requestObject": {"acctId": 331044988363}}
    private static final String REQ_MESSAGE = "{\"qryAccount\": {\"acctId\": %s}}";

    public AccountProxy(HttpClient httpClient) {
        super(httpClient);
    }

    @Override
    protected String handleResponse(String response) {
        DocumentContext sc = JsonPath.parse(response);
        Object object = sc.read("$.resultObject");
        String result = JSON.toJSONString(object, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteDateUseDateFormat);
        StringBuilder sb = new StringBuilder();
        sb.append("\"accountDetail\":" ).append(result).append("");
        return sb.toString();
    }

    @Override
    protected String getMessage(Long... params) {
        return String.format(REQ_MESSAGE,params);
    }
}
